package com.anolesoft.amljmes.fortyone.service.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.anolesoft.amljmes.fortyone.vo.MesOrderTraceBean;

@Mapper
public interface MesOrderTraceMapper {
	/**
	 * 查询制造记录当前工序信息
	 * @param fabrecordid
	 * @return
	 */
	@Select("select * from (\n" +
					"select\n" + 
					"     a.processname,a.processno,t.fabrecordid,rownum as aa  from mes_order_trace t\n" + 
					"    inner join mes_process_trace a on  t.objuid=a.ordertraceuid\n" + 
					"    where t.fabrecordid=#{fabrecordid, jdbcType=VARCHAR} and a.processstate=0\n" + 
					"order by case when length(regexp_substr(a.processno,'^\\s*[[:digit:]]+',1, 1)) > 0 then\n" +
					"     to_number(to_single_byte(regexp_substr(a.processno,'^\\s*[[:digit:]]+',1,1)))\n" + 
					"      else case when regexp_instr(a.processno, '[()]') > 0 then\n" + 
					"           to_number(regexp_replace(a.processno,'[()]','')) else 9999999 end end,\n" + 
					"           case when instr(a.processno, '-') > 0 then to_number(substr(a.processno,\n" + 
					"               instr(a.processno, '-') + 1)) else 0 end,\n" + 
					"           case when instr(a.processno, '') > 0 then to_number(substr(a.processno,\n" + 
					"               instr(a.processno, '') + 1)) else 0 end,\n" + 
					"           case when instr(a.processno, '') > 0 then to_number(substr(a.processno,\n" + 
					"                instr(a.processno, '') + 1)) else 0 end, a.processno\n" + 

					") where aa = 1")
	MesOrderTraceBean queryxiayigefongxu(String fabrecordid);
	
	/**
	 * 更新制造记录当前工序信息
	 * @param mesorder
	 * @return
	 */
	@Update("    update MES_ORDER_TRACE  set curgongxu = #{processno, jdbcType=VARCHAR},curgongxuname = #{processname, jdbcType=VARCHAR}  "
			+ "    where fabrecordid = #{fabrecordid, jdbcType=VARCHAR}")
	int updateCurgongxu(MesOrderTraceBean mesorder);
}
